home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 34 / Mac Magazin and MacEasy Magazine CD - Issue 34.iso / Grafik & Text / Alpha ƒ / Tcl / Modes / perl4.tcl < prev    next >
Text File  |  1996-08-15  |  5KB  |  139 lines

  1.  
  2. if {![info exists perlDocs]} {
  3.     set perlDocs "$HOME:Help:Perl Commands"
  4. }
  5.  
  6. ##############################################################################
  7. # Colorization setup
  8. #
  9. # Keywords are separated here according to their location in "Perl Commands",
  10. # for the convenience of the cmd-double-click mechanism.
  11. #
  12. # Expression words are described in the "Compound Statements" section
  13. #
  14. set perlExprWords {  
  15. else elsif for foreach if return unless until while eq ne cmp lt gt le ge
  16. }
  17.  
  18. # Special variables are described in their own section (and are not 
  19. # individually marked, so we have to search for them.)
  20. #
  21. # This group can safely be colorized...
  22. #
  23. set perlNameWords {
  24. @_ $_ $.  $/ $, $" $\\ $\# $% $= $- $~ $^ $| $$ $? $& $` $' $+ $* 
  25. $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $[ $] $; $! $@ $< $> $( $) $:
  26. }
  27.  
  28. #... while this group is forced lower-case by the current colorization scheme
  29. #
  30. set perlSpecialVars [concat $perlNameWords {
  31. $^D $^F $^I $^P $^T $^W $^X 
  32. $ARGV @ARGV @INC %INC @INC %ENV $SIG $ENV %SIG
  33. }]
  34.  
  35. # Perl operators and functions are indexed via the Marks menu
  36. #
  37. set perlKeyWords {
  38.     accept alarm atan2 bind binmode caller chdir chmod chop chown chroot 
  39.     close closedir connect continue cos crypt dbmclose dbmopen defined 
  40.     delete die do dump each   eof eval exec exit exp fcntl fileno 
  41.     flock  fork getc getlogin getpeername getpgrp getppid 
  42.     getpriority getgrnam gethostbyname getnetbyname getprotobyname getpwuid 
  43.     getgrgid getservbyname gethostbyaddr getnetbyaddr getprotobynumber 
  44.     getservbyport getpwent getgrent gethostent getnetent getprotoent 
  45.     getservent setpwent setgrent sethostent setnetent setprotoent setservent 
  46.     endpwent endgrent endhostent endnetent endprotoent endservent 
  47.     getsockname getsockopt gmtime goto grep hex  index int ioctl join keys 
  48.     kill last  length link listen local localtime log lstat lstat mkdir 
  49.     msgctl msgget msgsnd msgrcv next oct open opendir ord pack pipe pop 
  50.     print  printf  push q qq qx rand read readdir readlink recv redo
  51.      rename require reset  reverse rewinddir rindex rindex rmdir 
  52.     scalar seek seekdir select semctl semget semop send setpgrp setpriority 
  53.     setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep 
  54.     socket socketpair sort splice split sprintf sqrt srand stat study sub 
  55.     substr symlink syscall sysread system syswrite tell telldir time times 
  56.     tr truncate umask undef  unlink unpack unshift  utime values 
  57.     vec wait waitpid wantarray warn  write 
  58. }
  59. set perlWords [concat $perlKeyWords $perlNameWords $perlExprWords]
  60. regModeKeywords -e {#} -c red -k blue -s [set PerlmodeVars(stringColor)] Perl  $perlWords
  61. unset perlWords
  62.  
  63. ##############################################################################
  64. # Cmd-double-click support for Perl mode. 
  65. proc PerlDblClick {from to} {
  66.     global HOME perlKeyWords perlSpecialVars perlExprWords
  67.     global perlSearchPath
  68.     
  69.     set pc  [lookAt [expr $from - 1]]
  70.     set ppc [lookAt [expr $from - 2]]
  71.     set tc  [lookAt $to]
  72.     
  73.     # Extend selection to include special characters
  74.     #
  75.     if {$pc == {$}} { 
  76.         if {$from == $to} { incr to }
  77.         incr from -1
  78.         if {$tc == {^}} { incr to }
  79.         
  80.     } elseif {$pc == {^} && $ppc == {$}} {
  81.         incr from -2
  82.         
  83.     } elseif {$pc == {%} || $pc == {@}} {
  84.         incr from -1
  85.     }
  86.     
  87.     # Return if there's no selected text
  88.     if {$to > $from} {
  89.         select $from $to
  90.         set text [getSelect]
  91.         set qtext [quoteExpr $text]
  92.     } else {
  93.         return
  94.     }
  95.  
  96.     set perlSearchPath {}
  97.     
  98.     # Function call
  99.     if {$pc == "&"} {
  100.          if {![catch {search -f 1 -r 1 -m 0 -s "sub *$qtext *\{" 0} mtch]} {
  101.              pushMark
  102.              eval select $mtch
  103.              message "Use Ctl-. to return to original position"
  104.          } else {
  105.              message {Sub definition not found}
  106.          }
  107.  
  108.     # Look up keywords in the man page by their file marks
  109.     } elseif {[lsearch -exact $perlKeyWords $text] >= 0} {
  110.         editMark "$HOME:Help:Perl Commands" $text
  111.  
  112.     # Special vars aren't marked, so search for their definitions
  113.     } elseif {[lsearch -exact $perlSpecialVars $text] >= 0} {
  114.         if {[lsearch -exact [winNames] "Perl Commands"] >= 0} {
  115.             bringToFront "Perl Commands"
  116.         } else {
  117.             edit "$HOME:Help:Perl Commands"
  118.         }
  119.         if {![catch {search -f 0 -r 0 -m 0 -i 0 -s "     $text  " [maxPos]} mtch]} {
  120.             goto [lindex $mtch 0]
  121.         }
  122.  
  123.     # Flow control statements don't have separate entries
  124.     } elseif {[lsearch -exact $perlExprWords $text] >= 0} {
  125.         editMark "$HOME:Help:Perl Commands" "Compound statements"
  126.     
  127.     # If user clicked the arg of a 'require' command, open the file
  128.     } elseif {![catch {perlFindRequire $from $to} filename]} {
  129.         openPerlFile $filename
  130.  
  131.     # Other
  132.     } else {
  133.         select $from $to
  134.         message {Command-double-click on keywords, special vars, and req'd filenames}
  135.     }
  136.  
  137. }
  138.